#ifndef GAMEROOM_H
#define GAMEROOM_H

#include <QWidget>
#include <QSound>

enum class SnakeDirect
{
    UP = 0,
    DOWN,
    LEFT,
    RIGHT
};




class GameRoom : public QWidget
{
    Q_OBJECT
public:
    explicit GameRoom(QWidget *parent = nullptr);

    //重写绘图事件
    void paintEvent(QPaintEvent *event);

    void moveUp();

    void moveDown();

    void moveLeft();

    void moveRight();

    bool checkFail();

    void createNewFood();

    void setTimeout(int timeout) {moveTimeout = timeout;}

private:
    const int ksnakeNodeWidth = 20;
    const int ksnakeNodeHeight = 20;
    const int kDefaultTimeout = 200;

    QList<QRectF> snakeList;
    QRectF foodRect;

    SnakeDirect moveDirect = SnakeDirect::UP;
    QTimer *timer;

    bool isGameStart = false;

    QSound *sound;

    int moveTimeout = kDefaultTimeout;

};

#endif // GAMEROOM_H
